Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

chore: update devcontainer docker image #208

Merged
merged 11 commits into from
Sep 9, 2022
Merged

chore: update devcontainer docker image #208

merged 11 commits into from
Sep 9, 2022

Conversation

kratico
Copy link
Contributor

@kratico kratico commented Sep 5, 2022

Closes #41

Updates devcontainer docker image to install the following tools as vscode user

  • deno
  • dprint
  • node (needed for cspell)
  • cspell

Developer test plan

Using VSCode, start the project in a container

  • open a .ts file, and try go to Class/Interface definitions in other files using F12 (or command + click)
  • edit a .ts file, add many line breaks, and validate that dprint with the VSCode extension formats the text
  • open the VSCode terminal and run cspell "**/*"
  • open the VSCode terminal and run polkadot -V
  • open the VSCode terminal and run deno task run examples/transfer.ts

Using Gitpod, try the previous steps in

Ideas

As a follow up, we could create another image with the polkadot binary, so it can be used with test-util/config.ts ✅ done

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated
RUN export PATH="$DPRINT_INSTALL/bin:$PATH"
RUN /bin/bash -c 'curl -fsSL https://deno.land/x/install/install.sh | sh \
&& curl -fsSL https://dprint.dev/install.sh | sh \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \
Copy link
Contributor Author

@kratico kratico Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only used for cspell.

An alternative installation method could be to use node from NodeSource

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we still need to set up Node in order for Prettier and other devcontained extensions to work properly. I stackoverflowed this over a year ago. The answer is subpar. @tjjfvi any recommendations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not familiar with docker, but the setup seems fine to me 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use https://deb.nodesource.com/setup_18.x so we don't need to create a non-root user to run nvm.

Note: this would be an alternative to setup nvm as a root or non-root user https://github.com/microsoft/vscode-dev-containers/blob/v0.195.0/containers/javascript-node/.devcontainer/base.Dockerfile#L10

@kratico kratico force-pushed the chore/dev-container branch from 1a88635 to 349eb05 Compare September 6, 2022 17:20
Comment on lines 16 to 18
# Gitpod creates a gitpod user to run without privileges
# following https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ENV DENO_DIR=/home/gitpod/.deno
Copy link
Contributor Author

@kratico kratico Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I duplicated the Dockerfile as workaround for Gitpod.
Gitpod runs deno (or any script) as non-root user gitpod.
Setting DENO_DIR allows the gitpod user to store deno cache files in a folder where gitpod has write permissions.

Unfortunately, Gitpod, does not support docker multi-stage builds (see issue). With multi-stage support, a single Dockerfile could be used to target a build for Gitpod.

@kratico kratico added the feature label Sep 6, 2022
"editor.defaultFormatter": "dprint.dprint",
"editor.formatOnSave": true,
"editor.tabSize": 2,
"prettier.printWidth": 100
},
"extensions": [
"EditorConfig.EditorConfig",
"bungcip.better-toml",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of this as well, as I believe we no longer have any toml in this repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a book.toml file.
Shall I remove it anyway?

file: Dockerfile
file: .gitpod.Dockerfile
tasks:
- init: deno task star
vscode:
extensions:
- EditorConfig.EditorConfig
- bungcip.better-toml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@harrysolovay
Copy link
Contributor

Running in a vscode dev container, I get the following:

Screen Shot 2022-09-07 at 3 02 04 PM

Meanwhile, not sure why this is showing (should be auto-installed, if I'm not mistaken):

Screen Shot 2022-09-07 at 3 02 15 PM

@kratico
Copy link
Contributor Author

kratico commented Sep 7, 2022

Running in a vscode dev container, I get the following:

Screen Shot 2022-09-07 at 3 02 04 PM

Meanwhile, not sure why this is showing (should be auto-installed, if I'm not mistaken):

Screen Shot 2022-09-07 at 3 02 15 PM

@harrysolovay Did you rebuild the container?

I'm not able to reproduce
After rebuilding the image dprint is globally installed

root@04b98afd969d:/workspaces/capi# which dprint
/usr/local/bin/dprint

RUN export PATH=/usr/local/cargo/bin:$PATH
RUN export DPRINT_INSTALL="/home/vscode/.dprint"
RUN export PATH="$DPRINT_INSTALL/bin:$PATH"
FROM vscode as gitpod
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gitpod does not support multistage builds but VSCode devcontainer extension supports multi stage builds.

With this setup

  • gitpod, uses the last stage to configure the container image
  • devcontainer, uses the vscode stage configured in devcontainer.json

@harrysolovay
Copy link
Contributor

Do we want to remove this line as well and add a badge such as this?

@kratico
Copy link
Contributor Author

kratico commented Sep 9, 2022

@harrysolovay this is badge ready now 🎉

Gitpod Open

Open in Remote - Containers

@kratico kratico merged commit 3b59e2b into main Sep 9, 2022
@kratico kratico deleted the chore/dev-container branch September 9, 2022 15:33
harrysolovay pushed a commit that referenced this pull request Oct 19, 2022
* chore: update devcontainer docker image

* chore: remove rust extension from devcontainer.json and .gitpod.yml

* chore: update Dockerfile base image to denoland/deno

* chore: add custom docker image for Gitpod

* chore: unset DENO_DIR for Gitpod

* chore: set deno as container user

* chore: add multistage container

* chore: add polkadot binary

* chore: update Readme

* feat: update docker image to download polkadot from GH releases
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure optimal Docker, Devcontainer & Gitpod setup
3 participants